home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ISO_SRC.ZIP / LIBRARY.ZIP / FONT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-12  |  4.4 KB  |  173 lines

  1. /*  ERROR CHECK FOR DEFINES */
  2. #ifdef COMPILER_BORLAND
  3.   #ifdef COMPILER_WATCOM
  4.     #error MUST USE ONLY ONE COMPILER_ OPTION
  5.   #endif
  6. #else
  7.   #ifndef COMPILER_WATCOM
  8.     #error MUST USE COMPILER_ OPTION
  9.   #endif
  10. #endif
  11.  
  12. #ifndef __STDARG_H
  13. #include <stdarg.h>
  14. #endif
  15.  
  16. #define FONT_DEFAULT_COLOR 15
  17. #define FONT_DEFAULT_TRANS -1
  18.  
  19. //========================================================================
  20. //  VARIABLES
  21. //========================================================================
  22. signed short int font_height=8;
  23. signed short int font_width=8;
  24.  
  25. //char *font_ptr=(char *)0xf000fa6e;
  26. #ifdef COMPILER_BORLAND
  27. char *font_ptr=(char *)(0xf0000000);
  28. #endif
  29.  
  30. #ifdef COMPILER_WATCOM
  31. char *font_ptr=(char *)(0xf0000);
  32. #endif
  33.  
  34.  
  35. //========================================================================
  36. //  PROTOTYPES
  37. //========================================================================
  38. signed short int font_printxy(char *screen,signed short int x,signed short int y,char *text,...);
  39. void font_printc(char *screen,signed short int x,signed short int y,signed short int color,signed short int trans,char c);
  40.  
  41. //========================================================================
  42. //  FUNCTIONS
  43. //========================================================================
  44. signed short int font_printxy(char *screen,signed short int x,signed short int y,char *text,...)
  45. {
  46.   va_list valist;
  47.   char toprocess[200],*ptr;
  48.   unsigned short int length;
  49.   signed short int i,trans,color;
  50.   char c1,c2,chars[4];
  51.   signed short int xx,yy;
  52.  
  53.   va_start(valist,text);
  54.   vsprintf(toprocess,text,valist);
  55.   va_end(valist);
  56.  
  57.   length=0;
  58.   trans=FONT_DEFAULT_TRANS;
  59.   color=FONT_DEFAULT_COLOR;
  60.   ptr=toprocess;
  61.   xx=x;
  62.   yy=y;
  63.  
  64.   while(*ptr) {
  65.  
  66.     // pull out a character
  67.     c1=*ptr++;
  68.  
  69.     // is it an embedded command?
  70.     if(c1=='/') {
  71.  
  72.       // pull out the next character
  73.       if(!(c2=*ptr++))
  74.         return(length);
  75.  
  76.       switch(c2) {
  77.         // b is for background color
  78.         // pull out 3 number for a decimal value 0 to 255 (>255 is transparent)
  79.         case 'b': for(i=0;i<3;i++) {
  80.                     chars[i]=*ptr++;
  81.                     if(!chars[i])
  82.                       return(length);
  83.                     if((chars[i]<'0') || (chars[i]>'9'))
  84.                       chars[i]='0';
  85.                   }
  86.                   chars[3]=0;
  87.  
  88.                   trans=atoi(chars);
  89.                   if(trans<0)
  90.                     trans=0;
  91.                   if(trans>255)
  92.                     trans=-1;
  93.  
  94.                   break;
  95.  
  96.         // t is for drawing color
  97.         // pull out 3 number for a decimal value 0 to 255
  98.         case 't': for(i=0;i<3;i++) {
  99.                     chars[i]=*ptr++;
  100.                     if(!chars[i])
  101.                       return(length);
  102.                     if((chars[i]<'0') || (chars[i]>'9'))
  103.                       chars[i]='0';
  104.                   }
  105.                   chars[3]=0;
  106.  
  107.                   color=atoi(chars);
  108.                   if(color<0)
  109.                     color=0;
  110.                   if(color>255)
  111.                     color=255;
  112.  
  113.                   break;
  114.  
  115.         // n is for form feed  (move down 1 line)
  116.         case 'n': yy++;
  117.                   break;
  118.  
  119.         // r is for carriage return  (move to x)
  120.         case 'r': xx=x;
  121.                   break;
  122.  
  123.         // N is for form feed and carriage return (move to x, move down 1 line)
  124.         case 'N': xx=x;
  125.                   yy++;
  126.                   break;
  127.  
  128.         default: font_printc(screen,xx,yy,color,trans,c2);
  129.                  length++;
  130.                  xx+=font_width;
  131.                  break;
  132.       }
  133.     } else {
  134.       font_printc(screen,xx,yy,color,trans,c1);
  135.       length++;
  136.       xx+=font_width;
  137.     }
  138.   }
  139.  
  140.   return(length);
  141. }
  142.  
  143. void font_printc(char *screen,signed short int x,signed short int y,signed short int color,signed short int trans,char c)
  144. {
  145.   signed short int i,j,xx;
  146.   char mask;
  147.   char *cptr,*sptr;
  148.  
  149.   cptr = font_ptr + c * font_width + 0xfa6e;
  150.   screen+=(y<<6)+(y<<8)+x;
  151.  
  152.   i=0;
  153.   while(i++ < font_height && (unsigned short int)y < 200) {
  154.     xx=x;
  155.     mask=128;
  156.     sptr=screen;
  157.     j=0;
  158.     while(j++ < font_width && (unsigned short int)xx < 320) {
  159.       if(*cptr & mask)
  160.         *sptr=color;
  161.       else
  162.       if(trans!=-1)
  163.         *sptr=trans;
  164.       sptr++;
  165.       xx++;
  166.       mask>>=1;
  167.     }
  168.     cptr++;
  169.     screen+=320;
  170.     y++;
  171.   }
  172. }
  173.